<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="webjars/jquery/3.6.4/jquery.min.js"></script>
    <link href="webjars/bootstrap/5.2.3/css/bootstrap.min.css" rel="stylesheet">
    <script>
        $(function (){
            $(".btn-info").click(function (){
                location="add"
            })
            $(".btn-primary").click(function (){
                location="update?id="+$(this).val()
            })

            $("#all").click(function (){
                $("[name='chk']").prop("checked",$(this).prop("checked"));
            })
            $(".btn-warning").click(function (){
                //判断有选择
                var $name = $("[name='chk']:checked");
                if($name.length==0){
                    alert("对不起，请选择！");
                }else{
                   let values="";
                   $name.each(function (){
                       values+= $(this).val()+","
                   })
                    alert(values);
                    if(confirm("?")){
                        $.getJSON(
                            "delete?ids="+values,
                            function (obj){
                                alert(typeof(obj));
                                if(obj){
                                    alert("删除成功！");
                                    location.reload();
                                }else{
                                    alert("删除失败！");
                                }
                            }
                        )
                    }

                }
            })
        })
    </script>
</head>
<body>
    <div class="container">
         <form>

         </form>

          <h3><span th:text="${session.logUser.name}"></span></h3>
           花括号的方式：  [[${session.logUser.name}]]
          <hr>
        <table class="table table-bordered table-hover">
              <tr>
                  <th>
                      <input type="checkbox" id="all">全选
                      <button class="btn btn-warning">删除</button>
                  </th>
                  <th>序号</th>
                  <th>账号</th>
                  <th>密码</th>
                  <th>生日</th>
                  <th>性别</th>
                  <th>地址</th>
                  <th>
                      <button class="btn btn-info">新增</button>
                  </th>
              </tr>
            <tr th:each="user,index:${pager.list}" th:object="${user}">
                <td><input type="checkbox" name="chk" th:value="*{id}"> </td>
                <td th:text="${index.count}"></td>
                <td th:text="*{name}"></td>
                <td th:text="*{pwd}"></td>
                <td th:text="*{#dates.format(birthday,'yyyy-MM-dd')}"></td>
                <td th:text="*{sex}==0 ? '男':'女' "></td>
                <td th:text="*{address}"></td>
                <td>
                    <button class="btn btn-primary" th:value="*{id}">修改</button>
                </td>
            </tr>
            <tr>
                <td colspan="10" align="center">
                    共<span th:text="${pager.total}"></span>条数据，
                    共<span th:text="${pager.pages}"></span>页，
                    当前是第<span th:text="${pager.pageNum}"></span>页。

                    <a th:href="@{list(offset=1)}">首页</a>
                    <a th:if="${pager.hasPreviousPage}" th:href="@{list(offset=${pager.prePage})}">上页</a>
                    <a th:if="${pager.hasNextPage}" th:href="@{list(offset=${pager.nextPage})}">下页</a>
                    <a th:href="@{list(offset=${pager.pages})}">末页</a>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
